package net.jlibrary.example.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;

import net.jlibrary.common.core.annotation.CodeGenComment;
import net.jlibrary.common.core.annotation.Compositor;
import net.jlibrary.common.core.annotation.SearchCondition;
import net.jlibrary.common.core.annotation.SearchField;
import net.jlibrary.common.core.entity.BaseObject;

/**
 * 示例代码：图书管理
 * 
 * @author fzys
 *
 */
@Entity(name = "tab_book")
@BatchSize(size = 15)
@Compositor
@CodeGenComment(value = "图书管理", genSelect = true)
public class Book extends BaseObject {
	private static final long serialVersionUID = -8198353015224700158L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@SearchField(value = "id", condition = SearchCondition.EQUAL)
	private Long id;
	@Column(length = 50)
	@CodeGenComment(value = "书名", viewList = true, viewSearch = true, viewText = true, minLength = 2, maxLength = 50)
	private String name;
	@Column(length = 500)
	@CodeGenComment(value = "作者", viewList = true, required = true)
	private String author;
	@Column(length = 500)
	@CodeGenComment(value = "价格", viewList = true)
	private double price;
	@Column(length = 500)
	@CodeGenComment(value = "内容描述", viewList = true)
	private String description;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "classification_id")
	@CodeGenComment(value = "图书种类", viewList = true, viewSearch = true, required = true)
	private Classification classification;

	@Column(updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@CodeGenComment(value = "创建时间", viewList = true)
	private Date createdate;
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastdate;

	@SearchField(value = "name", condition = SearchCondition.FUZZ_RIGHT)
	@Transient
	private String nameSearchKey;

	@SearchField(value = "classification", condition = SearchCondition.EQUAL)
	@Transient
	private Classification classificationSearchKey;

	public Long getId() {
		return id;
	}

	@Override
	public Serializable getPrimaryKey() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	public Date getLastdate() {
		return lastdate;
	}

	public void setLastdate(Date lastdate) {
		this.lastdate = lastdate;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Book other = (Book) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public Classification getClassification() {
		return classification;
	}

	public void setClassification(Classification classification) {
		this.classification = classification;
	}

	public String getNameSearchKey() {
		return nameSearchKey;
	}

	public void setNameSearchKey(String nameSearchKey) {
		this.nameSearchKey = nameSearchKey;
	}

	public Classification getClassificationSearchKey() {
		return classificationSearchKey;
	}

	public void setClassificationSearchKey(Classification classificationSearchKey) {
		this.classificationSearchKey = classificationSearchKey;
	}
}
